﻿#region License
//  Distrubted Under the GNU Public License version 2 (GPLv2)
// ========================================
// 
//  QuizzMasterStudio Version 3 
//  Copyright © 2012 , The Sparks (Autism App Jam 2014)
//  All rights reserved.  
// 
// Robert Long, Zephyr Yao, Hillary Chansavang, Li Xiao, Arial Xiao
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//  
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//  The full license is also included in the root folder.
// 
// Robert Long
//  Email: rbtLong@live.com
#endregion

using System.ComponentModel;
using System.Windows.Controls;
using Core.Annotations;
using Core.Avatar;
using Core.Features.MainMenu;
using Core.User;
using Core.ViewModels;

namespace Core.ViewModel
{
    public class CoreCtrlVM : INotifyPropertyChanged
    {
        private readonly ContentPresenter _dlgPresnter;
        private readonly Turtle _turtle;
        private MainMenuDialog _menu;

        public string TotalScore
        {
            get
            {
                return string.Format("Total Points: {0}", 
                    UserProfileSession.GetSession().User.TotalScore);
            }
        }

        public CoreCtrlVM(ContentPresenter dlgPresnter, Turtle turtle)
        {
            _dlgPresnter = dlgPresnter;
            _turtle = turtle;
            subscribeTotalScore();
            initHelloDlg();
        }

            private void subscribeTotalScore()
            {
                UserProfileSession.GetSession().User.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == "TotalScore")
                        OnPropertyChanged("TotalScore");
                };
            }

            private void initHelloDlg()
            {
                var helloInit = new HelloDialogInitializer(_turtle, _dlgPresnter);
                helloInit.DialogFinished += (s, a) => 
                    new MainMenuInitializer(_menu, _dlgPresnter, _turtle);
            }


        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
